﻿using System;
using UnityEngine;

public static class StringHelper
{
    public static int ToShort(this Parameter target)
    {
        short value;
        short.TryParse(target.value, out value);
        return value;
    }
    public static int ToInt(this Parameter target)
    {
        int value;
        int.TryParse(target.value, out value);
        return value;
    }
    public static long ToLong(this Parameter target)
    {
        long value;
        long.TryParse(target.value, out value);
        return value;
    }
    public static bool ToBool(this Parameter target)
    {
        bool value;
        bool.TryParse(target.value, out value);
        return value;
    }
    public static DateTime ToDateTime(this Parameter target)
    {
        DateTime value;
        DateTime.TryParse(target.value, out value);
        return value;
    }
    public static double ToDouble(this Parameter target)
    {
        double value;
        double.TryParse(target.value, out value);
        return value;
    }
    public static float ToFloat(this Parameter target)
    {
        float value;
        float.TryParse(target.value, out value);
        return value;
    }

    public static Vector2 ToVector2(this Parameter target)
    {
        return JsonUtility.FromJson<Vector2>(target.value);
    }
    public static Vector3 ToVector3(this Parameter target)
    {
        return JsonUtility.FromJson<Vector3>(target.value);
    }
    public static Rect ToRect(this Parameter target)
    {
        return JsonUtility.FromJson<Rect>(target.value);
    }
}